﻿<%@ Page Culture="auto" UICulture="auto" Title="Service constraints (with session)"
    Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ServiceConstraintWithSession.aspx.cs"
    Inherits="BM.Tools.WebControls.MForm.Example.Constraints.ServiceConstraintWithSession" %>

<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls.Additions"
    TagPrefix="mfadd" %>
<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls"
    TagPrefix="mf" %>
<asp:Content runat="server" ContentPlaceHolderID="Demonstration">
    <p>
        Every time you provide a value, it must be higher than before. The previous value
        is stored in session.
    </p>
    <mf:RootValidator runat="server" ControlToValidate="Root1" />
    <mf:Root ID="Root1" runat="server">
        <Contents>
            <mf:Branch Name="SomeBranch" runat="server">
                <Contents>
                    <mf:Leaf Name="MustBeMore" runat="server">
                        <Additions>
                            <mfadd:ServiceConstraint ID="ServiceConstraint1" runat="server" ServiceMethod="MustBeGreaterThanBefore"
                                ServicePath="~/AutoComplete/AutoComplete.asmx">
                                <mfadd:ServiceParameter runat="server" Name="now" Path="." />
                            </mfadd:ServiceConstraint>
                        </Additions>
                    </mf:Leaf>
                </Contents>
            </mf:Branch>
        </Contents>
    </mf:Root>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="Description" runat="server">
    <p>
        The true potential of the <code>ServiceConstraint</code> control is unraveled, when
        it is used with session. This allows the user to dynamically validate the form content
        with the data that is session-specific. The following example shows such a use in
        a very simple example.
    </p>
    <p>
        In the AutoComplete webservice class, a simple method <code>MustBeGreaterThanBefore</code>
        has been written. The method is provided with <code>[WebMethod(true)]</code> custom
        attribute, which enables the web session. The method compares the value from the
        form with the value from session.
    </p>
    <p>
        The Leaf <code>MustBeMore</code> is provided with a service constraint that invokes
        the <code>MustBeGreaterThanBefore</code> method with a parameter of value from itself
        (the attribute <code>Path</code> of value <code>.</code> denotes self).
    </p>
    <p>
        Finally, after the click on the <code>NextPageButton</code>, the value aquired from
        the <code>MustBeMore</code> leaf is written to the session.
    </p>
    <p>
        This way, after each PostBack, to make the value of <code>MustBeMore</code> leaf
        valid, it has to be higher than before.
    </p>
</asp:Content>
